import { Button } from 'antd'
import { useState } from 'react'
import { useMount } from 'ahooks'

import { WijmoBase } from '../../Router/Wijmo'
import { useRequest } from 'alova/client'
import { Http } from '../../API'

import { RedoOutlined, SearchOutlined, ExportOutlined, SortAscendingOutlined, PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons'

const wijmoConfig = async ({ operator }) => {

    return ({
        get: 'getBuySuppliers',
        pos: 'posBuySuppliers',
        put: 'putBuySuppliers',
        del: 'delBuySuppliers',
        params: {
            pageIndex: 1,
            pageSize: 10,
        },
        initParameter: {
            group: [],
            sort: [],
            groupPanel: true,
            filter: true,
            addSum: true,
            addIndex: true,
            topText: 'Ω',
            btmText: 'Ψ',
        },
        configuration: {
            allowSorting: 'MultiColumn',
            isReadOnly: true,
            selectionMode: 5,
            allowMerging: "Cells"
        },
        optionsBtn: click => ([
            {
                key: '0',
                type: 'group',
                label: '数据操作',
                children: [
                    { key: 'added', label: <Button type='link' onClick={() => click('onAdded')}><PlusOutlined style={{ color: '#13c2c2' }} />新增数据</Button> },
                    { key: 'modify', label: <Button type='link' onClick={() => click('onModify')}><EditOutlined style={{ color: '#13c2c2' }} />修改选中数据</Button> },
                    { key: 'delete', label: <Button type='link' danger onClick={() => click('onDelete')}><DeleteOutlined />删除选中数据</Button> },

                ],
            },
            {
                key: '1',
                type: 'group',
                label: '数据查询',
                children: [
                    { key: 'refresh', label: <Button type='link' onClick={() => click('onRefresh')} ><RedoOutlined style={{ color: '#13c2c2' }} />刷新数据</Button> },
                    { key: 'search', label: <Button type='link' onClick={() => click('onSearch')} ><SearchOutlined style={{ color: '#13c2c2' }} />条件搜索</Button> },
                    { key: 'sort', label: <Button type='link' onClick={() => click('onSort')} ><SortAscendingOutlined style={{ color: '#13c2c2' }} />排序方式</Button> },
                ],
            },
            {
                key: '2',
                type: 'group',
                label: '导出数据',
                children: [
                    { key: '2-1', label: <Button type='link' onClick={() => click('onSaveAct')}><ExportOutlined style={{ color: '#13c2c2' }} />导出选中数据</Button> },
                    { key: '2-2', label: <Button type='link' onClick={() => click('onSaveAll')}><ExportOutlined style={{ color: '#13c2c2' }} />导出全部数据</Button> },
                ],
            },
        ]),

        sortCriteria: [
            { id: 1, label: '供应商名称', value: 'OSupplierName' },
            { id: 2, label: '联系人', value: 'OContactPerson' },
        ],
        columns: [
            {
                dataIndex: 'uuid',
                valueType: 'Hidden',
                hideInSearch: true
            },

            {
                title: '供应商',
                dataIndex: 'supplierName',
                valueType: 'Input',
                width: 240,
                align: 'center',
            },
            {
                title: '类别',
                dataIndex: 'category',
                valueType: 'Input',
                width: 240,
                align: 'center',
                hideInSearch: true,
            },
            {
                title: '联系人',
                dataIndex: 'contactPerson',
                valueType: 'Input',
                width: 240,
                align: 'center',
            },
            {
                title: '联系方式',
                dataIndex: 'contactInfo',
                valueType: 'Input',
                width: 240,
                align: 'center',
            },

            {
                title: '公司全称',
                dataIndex: 'fullName',
                valueType: 'Input',
                width: 240,
                align: 'center',
            },
            {
                title: '税号',
                dataIndex: 'taxNumber',
                valueType: 'Input',
                width: 240,
                align: 'center',
            },
            {
                title: '发票单位地址',
                dataIndex: 'companyAddress',
                valueType: 'Input',
                width: 240,
                align: 'center',
            },
            {
                title: '发票联系电话',
                dataIndex: 'phone',
                valueType: 'Input',
                width: 240,
                align: 'center',
            },
            {
                title: '银行名称',
                dataIndex: 'bankName',
                valueType: 'Input',
                width: 240,
                align: 'center',
            },
            {
                title: '银行账号',
                dataIndex: 'bankAccount',
                valueType: 'Input',
                width: 240,
                align: 'center',
            },
            {
                title: '收件地址',
                dataIndex: 'address',
                valueType: 'Input',
                width: 240,
                align: 'center',
            },

            {
                title: '关联用户',
                dataIndex: 'operatorUid',
                valueType: 'Select',
                valueEnum: await operator,
                fieldNames: { value: 'uid', label: 'ulName' },
                width: 240,
                align: 'center',
            },
            {
                title: '备注',
                dataIndex: 'remark',
                valueType: 'TextArea',
                width: 240,
                align: 'center',
                hideInSearch: true,
            },
            {
                title: '创建人姓名',
                dataIndex: 'createUserName',
                valueType: 'Input',
                width: 200,
                align: 'center',
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true
            },
            {
                title: '创建日期',
                dataIndex: 'createTime',
                valueType: 'Input',
                width: 200,
                align: 'center',
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true
            },
            {
                title: '修改人姓名',
                dataIndex: 'updateUserName',
                valueType: 'Input',
                width: 200,
                align: 'center',
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true
            },
            {
                title: '修改日期',
                dataIndex: 'updateTime',
                valueType: 'Input',
                width: 200,
                align: 'center',
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true
            },
        ],
    })
}

const GongYingShangInfo = () => {
    const [WijmoConfig, setWijmoConfig] = useState()
    const { send } = useRequest(() => Http({ url: 'getBuySupplierUserInfo' }), { immediate: false })
    useMount(async () => {
        const user = await send()
        setWijmoConfig(await wijmoConfig({ operator: user.list }))
    })
    return (
        <div>
            {WijmoConfig && <WijmoBase Config={WijmoConfig} />}
        </div>
    )
}

export default GongYingShangInfo